/*=========================================

===========================================*/

	.SECTION	.XBSS, BSS, XMEMORY

DELAY_LOOP_1:	.SPACE	2
DELAY_LOOP_2:	.SPACE	2

.INCLUDE 	"P33FJ16GS502.INC"
.INCLUDE 	"MACRO.INC"
.GLOBAL		_main

.TEXT




_main:
		NOP
		CALL	WREG_INITIAL
		CALL	OSC_INITIAL
		CALL 	ACLK_INITIAL
		CALL 	REFCLKO_INITIAL
		CALL 	TIMER_INITIAL
		CALL	AD_INITIAL
		CALL	PWM_INITIAL
		CALL	INIT_FIR
		CALL	INITIAL_PID
		CALL	INITIAL_IO
		CALL	I2C_INITIAL
		;MOVFF	COMMAND_V,IB_V  		
  		BSET	INTCON1,#NSTDIS		; Disable Interrupt nest 
		BSET	I2C1CON,#I2CEN
		BSET	PTCON,#PTEN
REDO:
	NOP
	GOTO REDO		


WREG_INITIAL:
	CLR	W0
	MOV	W0,	W14
	REPEAT	#12
	MOV	W0,	[++W14]
	CLR W14
	RETURN
	
	


DELAY:
	MOV #(-10), W0
	MOV	W0,	DELAY_LOOP_1
	
	DELAY_1:
		INC	DELAY_LOOP_1
		BRA C,	END_DELAY
	
		DELAY_2:
			INC	DELAY_LOOP_2
			BRA C,	DELAY_1
			GOTO	DELAY_2

END_DELAY:
	NOP
	RETURN